package cate.game.role.res.kingsacrifice;

import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.HashMap;
import java.util.Map;

@NoteClass("灵王祭祀职业")
public class KingSacrificeJobInfo {

	@NoteField("职业")
	public byte job;

	@NoteField("等级")
	public int level;

	@NoteField(value = "经验",detail = "升级后清除")
	public int exp;

	@NoteField("已使用的免费刷新次数")
	public int free;

	@NoteField("已使用的有偿刷新次数")
	public int pay;

	@NoteField(value = "商品",detail = "只记录有操作的商品")
	public Map<Integer,Item> items;

	public void initialize() {
		if (items == null) {
			items = new HashMap<>();
		}
	}

	public KingSacrificeJobInfo(byte job) {
		this.job = job;
	}

	public KingSacrificeJobInfo() {
	}

	public Item getItem(int itemId){
		return items.computeIfAbsent(itemId, Item::new);
	}

	public boolean buyAnyItem() {
		for (Item value : items.values()) {
			if(value.buy){
				return true;
			}
		}
		return false;
	}

	public void onDaySpan() {
		free = 0;
		pay = 0;
		items.clear();
	}

	@NoteClass("商品数据")
	public static class Item{

		@NoteField("商品id")
		public int itemId;

		@NoteField("已购买")
		public boolean buy;

		public Item(int itemId) {
			this.itemId = itemId;
		}

		public Item() {
		}
	}
}
